package generator.common

import org.apache.poi.hssf.usermodel.{HSSFSheet, HSSFWorkbook}
import org.apache.poi.xssf.usermodel.{XSSFSheet, XSSFWorkbook}

import java.io.{File, FileInputStream}

trait ExcelReader {
//  var excelFileName:String
  def read(fileName:String): FileInputStream = {
    val excelFile = new File(fileName)
    new FileInputStream(excelFile)
  }

  def readHSSFSheet(SheetIndex:Int=0,fileName:String): HSSFSheet = {

    val Workbook = new HSSFWorkbook(read(fileName))
    Workbook.getSheetAt(SheetIndex)
  }

  def readXSSFSheet(SheetIndex: Int = 0, fileName: String,SheetName: String): XSSFSheet = {
    val Workbook = new XSSFWorkbook(read(fileName))
    if (SheetName=="") {
      Workbook.getSheetAt(SheetIndex)
    } else {
      Workbook.getSheet(SheetName)
    }


  }


}
